# Maintainer: xihale <xihale.top@qq.com>
pkgname=listen1-git
pkgver=2.33.0.r0.gbbc3865
pkgrel=1
pkgdesc="Listen 1 可以搜索和播放来自多个主流音乐网站的歌曲，让你的曲库更全面。并支持收藏功能，方便的创建自己的歌单。"
arch=("x86_64")
license=('MIT')
depends=(nodejs)
makedepends=('git' 'electron' 'npm')
url="https://github.com/listen1/listen1_desktop"
source=("listen1::git+${url}.git"
	"listen1_chrome_extension::git+https://github.com/listen1/listen1_chrome_extension.git"
	"listen1.desktop")
sha512sums=('SKIP'
            'SKIP'
            '6376a689dbd7a1cc06abd9ecaa7074f373b139e9c5fe929c80486a0fac9468cea2a5fcc8806e2e4e9d67342eea83e39ac8bdb8485f920119484d88e1fe0fe362')

prepare()
{
    git -C "${srcdir}/${pkgname%-git}" clean -dfx
    cd "${srcdir}/${pkgname%-git}"
    git submodule init
    git config submodule.app/listen1_chrome_extension.url "$srcdir/listen1_chrome_extension"
    git -c protocol.file.allow=always submodule update
}


pkgver() {
    cd "${srcdir}/${pkgname%-git}"
    ( set -o pipefail
        git describe --long --tag --abbrev=7 2>/dev/null | sed 's/^v//g;s/\([^-]*-g\)/r\1/;s/-/./g' ||
        printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short=7 HEAD)"
    )
}

build() {
	cd listen1/app
	if command -v cnpm &>/dev/null; then
		cnpm i --production
	elif command -v pnpm &>/dev/null; then
		pnpm i -P
	else
		npm i --production
	fi
}

package() {
	install -Dm644 "${srcdir}/${pkgname%-git}.desktop" -t "${pkgdir}/usr/share/applications"

	cd listen1/app/listen1_chrome_extension
	install -Dm644 "./LICENSE" -t "${pkgdir}/usr/share/licenses/${pkgname%-git}"
	install -Dm644 "./images/logo.png" "${pkgdir}/usr/share/pixmaps/${pkgname%-git}.png"
	cd ..
	# Only 755 can build success!
	install -dm755 $pkgdir/opt/${pkgname%-git}/
	mv * $pkgdir/opt/${pkgname%-git}/
}
